<div class="search-bar">
    <ul>
        <li>单据状态：</li>
        <li>
            <select id="status" class="province floatleft select1">
                <option value="-1" selected="selected">全部</option>
                <option value="0">处理中</option>
                <option value="1">成功</option>
                <option value="2">失败</option>
            </select>
        </li>
        
        <li class="marginleft10">起止日期：</li>
        <li>
            <input id="startDate"> ~ 
            <input id="endDate">
        </li>
        
        <li>
            <button type="button" class="btn">搜索</button>
        </li>
        <div class="clear"></div>
    </ul>
</div>

<div class="records">
    <table class="table">
        <thead>
            <tr class="trcolor">
                <th style="width: 10%">时间</th>
                <th style="width: 10%">充值方式</th>
                <th style="width: 6%">金额</th>
                <th style="width: 6%">手续费/优惠奖励</th>
                <th>交易描述</th>
                <th style="width: 12%">单据状态</th>
                <th style="width: 6%">详情</th>
            </tr>
        </thead>
        <tbody id="paylist-tbody"><tr class="trcolor"><td colspan="7">暂无数据</td></tr></tbody>
    </table>
</div>

<div class="page_info">
    <div id="listPage" class="megas512 zxf_pagediv"></div>    
</div>
<div style="height:50px;"></div>

<script>
    (function() {
        $("#startDate").datepicker({format: 'yyyy-mm-dd'});
        $("#endDate").datepicker({format: 'yyyy-mm-dd'});

        $("#status").change(function() {
            Page.currPage = 1;
            queryChargeLogList(1);
        })

        var Page = new PageList();
        Page.pageSize = 15;
        Page.denyTrai = true;
        Page.jumpPage = function(page) {
            queryChargeLogList(page);
        }
        $(".search-bar .btn").click(function() {
            queryChargeLogList(1);
        });

        function queryChargeLogList(page) {
            var data = {
                owner: "",
                type: "deposit",
                pageSize: Page.getPageSize(),
                pageNum: page || 1,
            };
            Page.currPage = page || 1;
            if ($("#status").val() != '-1') data.state = $("#status").val();
            if ($("#startDate").val() != '') data.start = $("#startDate").val().trim();
            if ($("#endDate").val() != '') data.end = $("#endDate").val().trim();
            startLoading();
            CMD.query_account_log2(data, function(r) {
                stopLoading();
                Page.fillPages(r.count, r.number, r.page, r.size);
                fillChargeLogList(r.list);
            });
        }
        queryChargeLogList(1);

        function fillChargeLogList(list) {
            var table = $("#paylist-tbody"); table.empty();
            var count = 0;
            for (var i in list) {
                var d = list[i];
                if (count % 2 == 0)
                    var tr = $("<tr class='trcolor'></tr>");
                else
                    var tr = $("<tr></tr>");
                count++;

                tr.append('<td>' + d.start + '</td>');
                if (d.channel == 'handOper') tr.append('<td>人工充值<br>' + Util.convertChannel(d.channel2) + '</td>');
                else {
                    var c = Util.convertChannel(d.channel2);
                    if (d.channel3 == 'alipay') {
                        c += "<br>支付宝";
                    }
                    else if (d.channel3 == 'wechat') {
                        c += "<br>微信";
                    }
                    else if (d.channel3 == 'qq') {
                        c += "<br>QQ钱包";
                    }
                    else if (d.channel3 == 'bank') {
                        c += "<br>网银";
                    }
                    tr.append('<td>' + c + '</td>');
                }
                //tr.append('<td>' + Util.convertChannel(d.channel) + '</td>');
                tr.append('<td>' + d.amount/100 + '</td>');
                tr.append('<td>0</td>');

                // 交易描述
                var s = "通过__c__转入__v__元";
                s = s.replace(/__c__/, Util.convertChannel(d.channel2));
                s = s.replace(/__v__/, d.amount/100);
                tr.append('<td>' + s + '</td>');
                if (d.state == 0) tr.append('<td>处理中</td>');
                else if (d.state == 1) tr.append('<td>成功</td>');
                else if (d.state == 2) tr.append('<td>失败</td>');

                // 详情
                var l = '<a href="#" value="__v__">详情</a>'.replace(/__v__/, d.id);
                tr.append('<td>' + l + '</td>');
                table.append(tr);
            }
            if (Util.isEmpty(list)) {
                table.append("<tr><td colspan='7'>暂无数据</td></tr>");
                return;
            }

            $("#paylist-tbody a").click(function(e) {
                var id = $(e.currentTarget).attr("value");
                for (var i in list) {
                    if (list[i].id != id) continue;

                    // 弹出详情
                    popChargeDetail(list[i]);
                    break;
                }
            });
        }

        function popChargeDetail(data) {
            var str = '<div class="pop-detail">\
                <p>交易编号：__no__</p>\
                <p>处理时间：__t__</p>\
                <p>交易类型：充值 </p>\
                <p>交易金额：__amount__</p>\
                <p>活动奖励金额：0</p>\
                <p>手续费用：0</p>\
                <p>交易状态：__state__ </p>';
            str = str.replace(/__no__/, data.id);
            str = str.replace(/__t__/, data.end || data.start);
            str = str.replace(/__amount__/, data.amount/100);
            if (data.state == 0)
                str = str.replace(/__state__/, "等待审核");
            if (data.state == 1)
                str = str.replace(/__state__/, "充值成功");
            if (data.state == 2)
                str = str.replace(/__state__/, "充值失败");
            var memo = {};
            try {
                memo = JSON.parse(data.memo);
            } catch (e) {}
            
            if (data.channel == 'handOper') {
                // 人工充值
                if (data.channel2 == 'bank') {
					str += '<p>充值方式：银行转账</p>';
					str += '<p>卡号：' + (memo.account || '') + '</p>';
					str += '<p>持卡人：' + (memo.name || '') + '</p>';
                    str += '<p>备注码：' + (memo.code || '') + '</p>';
                    str += '<p>存款时间：' + (memo.time || '') + '</p>';
                    str += '<p>账号信息：' + (memo.requestAccount) + '</p>';
                }
                else if (data.channel2 == 'wechat') {
                    str += '<p>充值方式：微信转账</p>';
                    str += '<p>微信号：' + (memo.account || '') + '</p>';
					str += '<p>昵称：' + (memo.name || '') + '</p>';
                    str += '<p>备注码：' + (memo.code || '') + '</p>';
                    str += '<p>存款时间：' + (memo.time || '') + '</p>';
                    str += '<p>微信号：' + (memo.requestAccount || '') + '</p>';
                }
                else if (data.channel2 == 'alipay') {
                    str += '<p>充值方式：支付宝转账</p>';
                    str += '<p>支付宝账号：' + (memo.account || '') + '</p>';
					str += '<p>认证姓名：' + (memo.name || '') + '</p>';
                    str += '<p>备注码：' + (memo.code || '') + '</p>';
                    str += '<p>存款时间：' + (memo.time || '') + '</p>';
                    str += '<p>支付宝账号：' + (memo.requestAccount || '') + '</p>';
                    str += '<p>认证姓名：' + (memo.alipay || '') + '</p>';
                }
                else if (data.channel2 == 'cft') {
                    str += '<p>充值方式：QQ钱包转账</p>';
                    str += '<p>账号：' + (memo.account || '') + '</p>';
                    str += '<p>认证姓名：' + (memo.name || '') + '</p>';
                    str += '<p>备注码：' + (memo.code || '') + '</p>';
                    str += '<p>存款时间：' + (memo.time || '') + '</p>';
                    str += '<p>账号信息：' + (memo.requestAccount || '') + '</p>';
                }
            }
            else {
                // 在线充值
                str += '<p>充值方式：' + Util.convertChannel(data.channel2) + '</p>';
            }
            if (data.state == 2) {
                if (memo.reason != '') {
                    str += '<p>驳回原因：' + memo.reason + '</p>';
                }
            }
            str += '</div>';

            layer.open({
                type : 1,
                title : '充值详情',
                scrollbar : false,
                shade : [ 0.5 ],
                area : [ '500px', '440px' ],
                content : str
            });
            $(".layui-layer-content").css("height", "auto");
            $(function() {
                $("body").resize();
                setTimeout(function() {
                    $("body").resize();
                }, 150);
            })
        }
    })();
</script>